package am.NotenProgramm.objects;

import am.NotenProgramm.Frame.GradePro;

public class Profile {
	String name;
	Subject[] subjects;

	// Constructor for manual construction
	public Profile(String name, Subject[] subjects) {
		this.name = name;
		this.subjects = subjects;
	}

	// with autogenerate-String
	public Profile(String name, String stringToFeed, Subject[] subjects) {
		this.name = name;
		this.subjects = subjects;
		// Split String and Search for Variables
		String[] splitedElements = stringToFeed.split("<,>");
		for (int i = 0; i < splitedElements.length; i++) {
			/*
			 * if (splitedElements[i].startsWith("oralWeight=")) { oralWeight =
			 * Double.parseDouble(splitedElements[i] .substring(11));
			 * System.out.println("oralWeight set to " + oralWeight); } else if
			 * (splitedElements[i].startsWith("subjectWeight=")) { subjectWeight
			 * = Double.parseDouble(splitedElements[i] .substring(14));
			 * System.out.println("subjectWeight set to " + subjectWeight); }
			 */
		}
	}

	// Add/Remove Subject
	public void addSubject(Subject subject) {
		Subject[] tmpSubjects = subjects;
		subjects = new Subject[tmpSubjects.length + 1];
		for (int i = 0; i < tmpSubjects.length; i++) {
			subjects[i] = tmpSubjects[i];
		}
		subjects[subjects.length - 1] = subject;
	}

	public void removeSubjects(int number) {
		GradePro.myStream.deleteSubject(subjects[number].getName());
		Subject[] tmpSubjects = subjects;
		subjects = new Subject[tmpSubjects.length - 1];
		for (int i = 0; i < tmpSubjects.length; i++) {
			if (i < number) {
				subjects[i] = tmpSubjects[i];
			} else if (i > number) {
				subjects[i - 1] = tmpSubjects[i];
			}
		}
		GradePro.myStream.saveProfile(GradePro.myProfile);	
	}
	
	//Get String to save the Profile
	public String getString() {
		return "profileData=" + /* "var1=" + var1* + */"<,>";
	}

	//Getters and Setters
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Subject[] getSubjects() {
		return subjects;
	}

	public void setSubjects(Subject[] subjects) {
		this.subjects = subjects;
	}
	
	public void setSubject(Subject subject, int counter) {
		this.subjects[counter] = subject;
	}
}
